package com.steakliu.sun.boot.starter.helper;

import com.steakliu.sun.boot.starter.prop.ConfigCenterProperties;
import com.steakliu.sun.boot.starter.prop.Prop;
import com.steakliu.sun.configcenter.api.ConfigCenterConfig;
import com.steakliu.sun.configcenter.api.ConfigCenterService;
import com.steakliu.sun.configcenter.api.ConfigInfoTransfer;
import com.steakliu.sun.spi.loader.ExtensionLoader;

/**
 * 功能说明：
 * <p>
 * Original @Author: steakliu-刘牌, 2023-02-08  17:41
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
public class ConfigInfoHelper {

    public static Prop getProp(ConfigCenterProperties properties) throws Exception {
        ConfigCenterService configCenterService = ExtensionLoader.getExtension(ConfigCenterService.class, properties.getType());
        configCenterService.init(new ConfigCenterConfig(properties.getAddress(),
                properties.getConfigId(), properties.getGroup()));

        String config = configCenterService.getConfig(new ConfigCenterConfig(properties.getAddress(),
                properties.getConfigId(), properties.getGroup()));

        return ConfigInfoTransfer.ymlTo(config, Prop.class);
    }
}
